package com.bflow.web.util;

import com.bflow.api.bo.ext.BflowUserBo;
import com.bflow.impl.BflowExtResServiceImpl;
import com.bflow.util.AssertUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Name 测试登录工具类
 * @Author haowen
 * @Date 2018-12-18
 */
public class TestLoginUtil {

    private static Map<String, BflowUserBo> USER_SESSION = new ConcurrentHashMap<>();

    /**
     * 登录
     * @param req
     * @param userId
     */
    public static void login(HttpServletRequest req, String userId){
        Map<String, BflowUserBo>  map =  BflowExtResServiceImpl.USER_LIST;
        String ssid = req.getSession().getId();
        USER_SESSION.put(ssid, map.get(userId));
    }

    /**
     * 获取 用户
     * @param req
     * @return
     */
    public static BflowUserBo getUser(HttpServletRequest req){
        Map<String, BflowUserBo>  map =  BflowExtResServiceImpl.USER_LIST;
        String ssid = req.getSession().getId();
        BflowUserBo userBo = USER_SESSION.get(ssid);
        AssertUtil.isTrue(userBo!=null, "未登录, 请先选择用户登录");
        return userBo;
    }


}
